<template>
  <div style="font-size: 12px; line-height:60px ; display: flex">

    <div style="flex:1; font-size: 20px">
      <span  style="cursor: pointer; font-size: 20px" @click="collapse"></span>
      <!--页签:class="collapseBtnClass"-->
      <el-breadcrumb separator="/" style="display: inline-block; margin-left: 10px" >
        <el-breadcrumb-item :to="item.path" v-for="item in paths">{{item.name}}</el-breadcrumb-item>
      </el-breadcrumb>

    </div>

    <el-dropdown style="width: 100px;cursor: pointer">
      <div>
        <img :src="user.avatar" style="width: 30px; border-radius: 50%; position: relative; top: 10px; right: 5px">
        <span>{{user.nickname }}</span> <i class="el-icon-arrow-down" style="margin-left: 5px"></i>
      </div>

      <el-dropdown-menu slot="dropdown" style="width: 100px; text-align: center">
        <el-dropdown-item style="font-size: 14px; padding: 5px 0">
          <router-link to="/person">个人信息</router-link>
        </el-dropdown-item>
        <el-dropdown-item style="font-size: 14px; padding: 5px 0">
          <span  style="text-decoration: none" @click="logout">退出</span>
        </el-dropdown-item>
      </el-dropdown-menu>
    </el-dropdown>
  </div>
</template>

<script>
export default {
  name: "Header",
  props: {
    collapseBtnClass: String,
    isCollapse: Boolean
  },
  data(){
    return {
      paths: [],
      user: localStorage.getItem("user") ? JSON.parse(localStorage.getItem("user")) : {nickname: '管理员'}
    }
  },
  methods: {
    collapse() { //点击收缩按钮的时候就将侧边栏收缩
      console.log("77777777777777")
      this.isCollapse = !this.isCollapse
      if (this.isCollapse) {
        this.logoTextShow = false
        this.sideWidth = 64
        this.collapseBtnClass = 'el-icon-s-unfold'
      } else {
        this.sideWidth = 200
        this.collapseBtnClass = 'el-icon-s-fold'
        this.logoTextShow = true
      }
    },
    logout(){//用户退出登录
      //1.发送请求给后端，退出登录
      this.request.get("admin/logout").then(res =>{
          if (res.state == 200){
            //2.先将页面退到登录页面
            this.$router.push("/login")
            //3.将浏览器保存的用户信息清除
            localStorage.removeItem("user")
            this.$message.success( res.message)
          }else {
            this.$message.success( "退出登陆失败，请稍后再试")
          }
      })

    }
  }
}
</script>

<style scoped>

</style>